package com.cloudm.technician.ui.modules.cloudm_box.pic_preview

import android.os.Bundle
import android.view.MenuItem
import com.cloudm.technician.R
import com.cloudm.technician.extensions.addFragmentToActivity
import com.cloudm.technician.ui.base.BaseActivity

/**
 * 作者: wesley
 * 时间: 2017/12/23
 * 描述: 照片预览界面
 */
class PicPreviewActivity : BaseActivity() {

    private var url: String = ""

    private var fragment: PicPreviewFragment? = null


    override val optionsMenuEnabled: Boolean
        get() = true

    override val menuRes: Int
        get() = R.menu.menu_pic_preview


    override fun handleBundle(bundle: Bundle) {
        url = bundle.getString("url")
    }

    override fun initVariables() {

    }

    override fun initViews(savedInstanceState: Bundle?) {
        headerTitle = R.string.pic_preview
        displayHomeAsUpEnabled = true

        fragment = manager.findFragmentById(
                R.id.common_content) as? PicPreviewFragment ?: PicPreviewFragment.newInstance(url)
        addFragmentToActivity(manager, fragment)

    }

    override fun initListener() {

    }


    override fun onOptionsItemSelected(item: MenuItem?): Boolean {
        return when (item?.itemId) {
            R.id.menu_delete -> {
                fragment?.deleteImage()
                true
            }

            else -> {
                false
            }
        }
    }
}